#ifndef CLOCKCONTROLLER_H
#define CLOCKCONTROLLER_H

// Qt lib import
#include <QObject>
#include <QAbstractListModel>
#include <QDebug>
#include <QString>
#include <QNetworkReply>
#include <QJsonValue>
#include "clockstatslotmodel.h"
#include "clockstatcalendarmodel.h"

class ClockController: public QObject
{
    Q_OBJECT

    Q_PROPERTY(ClockStatSlotModel *clockStatSlotModel READ clockStatSlotModel CONSTANT)
    Q_PROPERTY(ClockStatCalendarModel *clockStatCalendarModel READ clockStatCalendarModel CONSTANT)
    Q_PROPERTY(QString userId READ clockUserId WRITE setClockUserId)
    Q_PROPERTY(QString place READ clockPlace WRITE setClockPlace)
    Q_PROPERTY(QString fileUrl READ clockFileUrl WRITE setClockFileUrl)
public:
    //签到提交表单
    struct ClockForm {
        QString userId;
        QString place;
        QString fileUrl;
    };

    explicit ClockController(QObject *parent = 0);

    ClockStatSlotModel *clockStatSlotModel();
    ClockStatCalendarModel *clockStatCalendarModel();

    QString clockUserId();
    void setClockUserId(QString userId);

    QString clockPlace();
    void setClockPlace(QString place);

    QString clockFileUrl();
    void setClockFileUrl(QString fileUrl);

signals:
    void sig_req_finished();
    void sig_req_error(QString msg);
    void sig_req_success();
public slots:
    //获取考勤月历
    void slot_statcalendar_req(QString user_id);
    void slot_statcalendar_res(QNetworkReply *reply);
    //获取考勤足迹
    void slot_statslot_req(QString user_id);
    void slot_statslot_res(QNetworkReply *reply);
    //获取今日考勤统计
    void slot_stattoday_req(QString user_id);
    void slot_stattoday_res(QNetworkReply *reply);
    //提交考勤
    void slot_clock_req();
    void slot_clock_res(QNetworkReply *reply);
private:

    ClockStatSlotModel *_clockStatSlotModel;
    ClockStatCalendarModel *_clockStatCalendarModel;
    ClockForm *_clockForm;
    QNetworkAccessManager *_nam;

    QJsonValue get_reply_data(QNetworkReply * reply);
};
#endif // CLOCKCONTROLLER_H
